package com.common.util.antihijack;

import android.support.multidex.MultiDexApplication;
import android.widget.Toast;

import com.common.util.R;
import com.common.util.utils.AppUtils;
import com.common.util.utils.CrashHandler;
import com.common.util.utils.SecurityManager;

/**
 * @文件名称：AntiHiJackApplication.java
 * @文件作者：ljb
 * @文件描述：反劫持,当受到劫持时及时提醒用户
 * @版本： 1.0.0
 * @创建时间：2017-12-18 11:27
 * @修改历史：2017-12-18 11:27
 */

public class AntiHiJackApplication extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        if (AppUtils.isInMainProcess()) {
            this.registerActivityLifecycleCallbacks(new AppLifecycleCallback());
            addAppEventListener();
            if (SecurityManager.getManager().isRootSystem()) {
                Toast.makeText(this, "检测到您开放了手机系统权限", Toast.LENGTH_SHORT).show();
            }
        }
    }

    private void addAppEventListener() {
        AppEventManager.getInstance().addAppEventListener(new AppEventManager.AppEventListener() {
            @Override
            public void onAppStateChange(boolean front) {
                if (!front) {
                    Toast.makeText(getBaseContext(), getString(R.string.enter_background_running, AppUtils.getApplicationLabel()), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
